home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: catchSignals.c,v $
- * $Revision: 1.2 $
- * $Date: 1996/05/04 23:51:46 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
- #include "sysdefs.h"
- #include "queue_consist.h"
- #include "ess.h"
- #include "checking.h"
- #include "list.h"
- #include "error.h"
- #include "tid.h"
- #include "pool.h"
- #include "io.h"
- #include "bitvec.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "disk.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "latch.h"
- #include "bf.h"
- #include "link.h"
- #include "volume.h"
- #include "trace.h"
- #include "msgvector.h"
-
- #include "disk_funcs.h"
- #include "queues.h"
- #include "diskproc_globals.h"
- #include "diskproc_intfuncs.h"
- #include "diskproc_extfuncs.h"
-
- #ifdef linux
- #include <bsd/signal.h>
- #endif
-
- static void unexpected(int,int);
- static void quiet(int,int);
-
- /* whatever is not included here, doesn't get touched. */
- struct siginfo {
- int sig;
- char *string;
- int error_type;
- void (*sv_handler)(int,int);
- } siginfo[] = {
- { 0, "<none>", TYPE_FATAL, unexpected },
- { SIGHUP, "SIGHUP", TYPE_FATAL, unexpected },
- { SIGINT, "SIGINT", TYPE_QUIET, quiet }, /* ^C */
- { SIGQUIT, "SIGQUIT", TYPE_FATAL, unexpected },
- { SIGILL, "SIGILL", TYPE_FATAL, unexpected },
- { SIGTRAP, "SIGTRAP", TYPE_FATAL, unexpected },
- { SIGIOT, "SIGIOT", TYPE_FATAL, unexpected },
- #ifndef linux
- { SIGEMT, "SIGEMT", TYPE_FATAL, unexpected },
- #endif linux
- { SIGFPE, "SIGFPE", TYPE_FATAL, unexpected },
- { SIGKILL, "SIGKILL", 0, (void (*)(int,int))SIG_DFL },
- { SIGBUS, "SIGBUS", TYPE_FATAL, unexpected },
- { SIGSEGV, "SIGSEGV", TYPE_FATAL, unexpected }, /* abort() */
- #ifndef linux
- { SIGSYS, "SIGSYS", TYPE_FATAL, unexpected } ,
- #endif linux
- { SIGPIPE, "SIGPIPE", TYPE_QUIET, quiet }, /* serv exited */
- { SIGALRM, "SIGALRM", 0, (void (*)(int,int))SIG_DFL },
- { SIGTERM, "SIGTERM", 0, (void (*)(int,int))SIG_DFL },
- { SIGURG, "SIGURG", TYPE_FATAL, unexpected },
- { SIGSTOP, "SIGSTOP", 0, (void (*)(int,int))SIG_DFL },
- { SIGTSTP, "SIGTSTP", 0, (void (*)(int,int))SIG_DFL },
- { SIGCONT, "SIGCONT", 0, (void (*)(int,int))SIG_DFL },
- { SIGCHLD, "SIGCHLD", TYPE_FATAL, unexpected },
- { SIGTTIN, "SIGTTIN", 0, (void (*)(int,int))SIG_IGN },
- { SIGTTOU, "SIGTTOU", 0, (void (*)(int,int))SIG_IGN },
- { SIGIO, "SIGIO", TYPE_FATAL, unexpected },
- #ifdef hpux
- { SIGPWR, "SIGPWR", TYPE_FATAL, unexpected },
- /* this signal cannot be caught in HP-UX */
-
- /*{ _SIGRESERVE, "SIGRESERVE", TYPE_FATAL, unexpected },*/
- #else
- { SIGXCPU, "SIGXCPU", TYPE_FATAL, unexpected },
- { SIGXFSZ, "SIGXFSZ", TYPE_FATAL, unexpected },
- #endif hpux
- { SIGVTALRM,"SIGVTALRM",TYPE_FATAL, unexpected },
- { SIGPROF, "SIGPROF", 0, (void (*)(int,int))SIG_DFL },
- { SIGWINCH, "SIGWINCH", 0, (void (*)(int,int))SIG_DFL },
- #ifndef linux
- { SIGLOST, "SIGLOST", TYPE_FATAL, unexpected },
- #endif linux
- { SIGUSR1, "SIGUSR1", TYPE_FATAL, unexpected },
- { SIGUSR2, "SIGUSR2", TYPE_FATAL, unexpected },
- { 0, 0, 0}
- };
-
- static void
- quiet(
- int sig,
- int code
- )
- {
- TRPRINT(TR_DISKRW, TR_LEVEL_1, ("sig %d, code %d", sig, code));
-
- SM_ERROR(siginfo[sig].error_type, esmUNIXSIGNAL);
- }
-
- static void
- unexpected(
- int sig,
- int code
- )
- {
- fprintf(stderr, "DISKRW %s: signal %6s signal code %d\n",
- # ifdef DEBUG
- DiskName,
- # else DEBUG
- "",
- # endif DEBUG
- siginfo[sig].string, code);
- SM_ERROR(siginfo[sig].error_type, esmUNIXSIGNAL);
- }
-
-
-
- void
- catchSignals()
- {
- extern int errno;
- struct sigvec sv;
- register int i, s;
-
- TRACE(TR_DISKRW, TR_LEVEL_1);
-
- sv.sv_mask = 0; /* or-ed in with mask for current signal */
- sv.sv_flags = 0; /* don't use sigstack */
-
- for(i=1; i<NSIG && siginfo[i].sig != 0; i++) {
- TRACE(TR_DISKRW, TR_LEVEL_1);
- /*
- * Cast to no-arg func so it compiles. Maybes someday someone
- * will fix signal.h to declare sv_handler properly.
- */
- #if defined(DOTDOTDOT) || defined(hpux)
- /* Sun C++ defines DOTDOTDOT */
- if((sv.sv_handler = (void (*)(...))siginfo[i].sv_handler)
- == (void (*)(...))SIG_DFL)
- #elif defined(linux)
- if((sv.sv_handler = (__sighandler_t)siginfo[i].sv_handler)
- == SIG_DFL)
- #else
- if((sv.sv_handler = (void (*)())siginfo[i].sv_handler)
- == (void (*)())SIG_DFL)
- #endif
- continue; /* don't bother */
- s = siginfo[i].sig;
- if (s == 0) {
- break; /* end of signal list */
- }
- #ifdef hpux
- if(sigvector(s, &sv, 0 /* don't care about old vector */) < 0) {
- #else
- if(sigvec(s, &sv, 0 /* don't care about old vector */) < 0) {
- #endif hpux
- TRPRINT(TR_DISKRW, TR_LEVEL_1, ("sigvec failure on sig %d",i));
- SM_ERROR(TYPE_FATAL, errno);
- }
- }
- TRACE(TR_DISKRW, TR_LEVEL_1);
- }
-
- void
- unCatchAbortSignal(
- int sig
- )
- {
-
- #ifdef notdef
-
- struct sigvec sv;
-
- TRPRINT(TR_DISKRW, TR_LEVEL_1, ("sig %d", sig));
- sv.sv_mask = 0; /* or-ed in with mask for current signal */
- sv.sv_flags = 0; /* don't use sigstack */
- sv.sv_handler = (void (*)())SIG_DFL;
-
- if(sigvec(sig, &sv, 0 /* don't care about old vector */) < 0) {
- perror("sigvec"); /* to avoid loops we don't call SM_ERROR */
- onexit(errno);
- }
- #else
- /* This only gets called right before abort so we'd better
- * change the *current* mask.
- */
- if(sigsetmask( ~(1<<(sig-1)) ) < 0) {
- perror("sigsetmask");
- onexit(errno);
- }
- #endif
-
- }
-